package com.regular.utils.system;

import java.util.ArrayList;
import java.util.List;

import com.regular.mvc.admin.model.Module;
import com.regular.mvc.admin.model.TreeVO;

public class BasicUtils {
	
	private Integer len;
	
	public Integer getLen() {
		return len;
	}
	public void setLen(Integer len) {
		this.len = len;
	}
	
	public void checkLeaf(List<Module> parentMo,List<Module> missMo,List<TreeVO> treeVO){
		List<Module> newmiss = new ArrayList<Module>();
		List<Module> temporaryMo = new ArrayList<Module>();
		for (Module miss : missMo) {
			for (Module parent : parentMo) {
				boolean b = true;
				if(parent.getId()==miss.getId()){
					b=false;
					break;
				}
				if(parent.getId()==miss.getParentId()){
					List<Module> list = parent.getModule();
					if(list==null)
						list = new ArrayList<Module>();
					list.add(miss);
					--len;
					parent.setModule(list);
					for (TreeVO t : treeVO) {
						TreeVO tree = TreeVO.getInstance(miss);
						tree.setUrl(miss.getUrl());
						List<TreeVO> trees = new ArrayList<TreeVO>();
						if(t.getId()==miss.getParentId()){
							t.setChildren(trees);
						}
					}
					b=false;
					break;
				}
				temporaryMo = parent.getModule();
				if(b&&temporaryMo!=null&&len>0){
					newmiss.add(miss);
					checkLeaf(temporaryMo,newmiss,treeVO);
				}
			}
		}
	}
}
